package ru.acme.lab11.domain.account;

import ru.acme.lab11.exceptions.NotEnoughFundsException;

abstract public class AbstractAccount implements IAccount {
	
	private int balance;
	
	public int getBalance() {
		return balance;
	}
	
	public int getMaxWithdraw() {
		return getBalance();
	}
	
	public void deposit(int amount) {
		balance += amount;
	}
	
	public void withdraw(int amount) throws NotEnoughFundsException {
		if (balance < amount) {
			throw new NotEnoughFundsException(amount - balance, this);
		}
		balance -= amount;
	}
	
	public AbstractAccount(int balance) {
		if (balance < 0) {
			throw new IllegalArgumentException();
		}
		this.balance = balance;
	}

	public int maximumAmountToWihdraw() {
		return balance;
	}
	
}
